package secondary_classes;
import java.util.Comparator;

import junit.framework.Assert;



public class AskComparatorPriceTime implements Comparator<Order> {

	@Override
	public int compare(Order arg0, Order arg1) {
		int result = 0;
		
		Assert.assertTrue((arg0.getBidOrAsk()).equals("A"));
		Assert.assertTrue((arg1.getBidOrAsk()).equals("A"));
		
		if(arg0.getAskId().equals(arg1.getAskId())) {
			return 0;
		}
		
		if (arg0.getPrice().equals(arg1.getPrice())) { // if prices are the same, check dates
			if (arg0.getDate().before(arg1.getDate())) {
				result = -1;
			} else if (arg0.getDate().after(arg1.getDate())) {
				result = 1;
			} else { // if dates are the same, check time
				if (arg0.getTime().before(arg1.getTime())) {
					result = -1;
				} else if(arg0.getTime().after(arg1.getTime())) {
					result = 1;
				} else {
					result = 1;
				}
			}
		} else if (arg0.getPrice().compareTo(arg1.getPrice()) < 0) {
			result = -1;
		} else if (arg0.getPrice().compareTo(arg1.getPrice()) > 0) {
			result = 1;
		}
		
		return result;
	}

	

}
